package edu.hawaii.duedates;

import java.util.List;
import java.util.ArrayList;

/**
 * Command line parser class.
 * 
 * @author Daniel Tian
 * @author Aric West
 * 
 */
public class CommandLineParser {
  private final List<DueDatesOption> optionList = new ArrayList<DueDatesOption>();
  
  /**
   * Constructor. Goes through all the command-line arguments and creates instances of all the
   * lender classes and passes the proper fields to them.
   * 
   * @param theArgs the arguments from the command line
   */
  public CommandLineParser(String[] theArgs) {
    List<String> argList = new ArrayList<String>();
    
    if (theArgs.length > 0) {
      for (int i = 0; i < theArgs.length; i++) {
        if (theArgs[i].startsWith("-")) {
          argList.add(theArgs[i++]);
          
          while (i < theArgs.length && !theArgs[i].startsWith("-")) {
            argList.add(theArgs[i]);
            i++;
          }
          
          DueDatesOption option = new DueDatesOption(argList);
          optionList.add(option);
          argList.clear();
          i--;
        }
      }
    }
  }
  
  /**
   * Returns the list of all CommandFields objects parsed from args.
   * 
   * @return The list.
   */
  public List<DueDatesOption> getOptions() {
    return this.optionList;
  }
}
